package com.lp.security.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lp.common.wechat.mapper.WechatMapper;
import com.lp.common.wechat.model.entity.Wechat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: biz
 * @description:
 * @author: Ke.Song
 * @since: 2024-03-11 21:45:03
 */
@Slf4j
@Configuration
public class WxMaConfiguration {

    @Autowired
    private WechatMapper wechatMapper;

    @Bean
    public WxMaService wxMaService() {
        Wechat wechat = wechatMapper.selectOne(new QueryWrapper<>());
        WxMaService maService = new WxMaServiceImpl();
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
        wxMaConfig.setAppid(wechat.getAppId());
        wxMaConfig.setSecret(wechat.getAppSecret());
        maService.setWxMaConfig(wxMaConfig);
        return maService;
    }
}
